package zhoufu.sz.sanxiao_check.presents;

import android.text.TextUtils;
import java.util.List;
import javax.inject.Inject;
import zhoufu.sz.sanxiao_check.R;
import zhoufu.sz.sanxiao_check.models.BaseModel;
import zhoufu.sz.sanxiao_check.net.BasicRequestRepository;
import zhoufu.sz.sanxiao_check.net.RequestHelper;
import zhoufu.sz.sanxiao_check.ui.contract.BasicMsgItem2Contract;
import zhoufu.sz.sanxiao_check.utils.UIUtils;

/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/8/4
 */
public class AddTrainPresenter implements BasePresent
{

    private BasicRequestRepository repository;

    private BasicMsgItem2Contract.View view;

    @Inject
    public AddTrainPresenter(BasicRequestRepository repository)
    {
        this.repository = repository;
    }

    public void bindView(BasicMsgItem2Contract.View view)
    {
        this.view = view;
    }

    @Override public void onStart()
    {

    }

    @Override public void onPause()
    {

    }

    @Override public void onDestroy()
    {

    }

    public void save(String title, String content, List<String> path)
    {
        if ( TextUtils.isEmpty(title) )
        {
            view.showToast(UIUtils.getString(R.string.hint_title));
            return;
        }
        if ( TextUtils.isEmpty(content) )
        {
            view.showToast(UIUtils.getString(R.string.hint_train_content));
            return;
        }
        if ( path.size() == 0 )
        {
            view.showToast("请上传培训照片");
            return;
        }
        repository.AddStreetTrain(view.SID(), title, content, TextUtils.join(",", path),
                new RequestHelper.RequestCallBack<BaseModel>()
                {
                    @Override public void onPullStart()
                    {
                        view.pullStart();
                    }

                    @Override public void onPullFailud(Throwable throwable)
                    {
                        view.pullFaild();
                    }

                    @Override public void onPullEnd()
                    {
                        view.pullEnd();
                    }

                    @Override public void onPullSuccessed(BaseModel s)
                    {
                        if ( s.isSuccess() )
                        {
                            view.updateSuccese();
                        } else
                        {
                            view.showToast(s.getErrMsg());
                        }
                    }
                });
    }
}
